(function ($) {
    jQuery(document).ready(function () {
        $('#cform').submit(function () {
            if ($('#name').val()==""){
                alert("用户名不能为空")
                return false;
            }
            if ($('#email').val()==""){
                alert("密码不能为空")
                return false;
            }
            var action = '/userAction/login';
            $("#message").slideUp(750, function () {
                $('#message').hide();
                $('#submit')
                    .before('<img src="../images/ajax-loader.gif" width="20px" height="20px" class="contact-loader" />')
                    .attr('disabled', 'disabled');
//TODO 未加非空校验
                    $.post(action, {
                            username: $('#name').val(), //设置账号
                            password: $('#email').val(),//设置密码
                            identifcode: $('#identifcode').val()//设置为验证码
                        },
                        function (data) {
                            console.info(data);
                            if (!data.success) {
                                document.getElementById('message').innerHTML = data.message;
                                $("#message").css('color', 'red');
                                $('#message').slideDown('slow');
                                $('#cform img.contact-loader').fadeOut('slow', function () {
                                    $(this).remove()
                                });
                                $('#submit').removeAttr('disabled');
                            } else {
                                location.href = '/myindex.html';
                                return false;
                            }

                        }
                    );

            });
            return false;
        });

    });

}(jQuery));